import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: {},
		token:"",
		exp_time:0
	},
	mutations: {
		login(state, provider) {
			
			state.hasLogin = true;
			state.userInfo = provider.user_info;
			state.token = provider.token;
			state.exp_time = provider.exp_time;
			
			uni.setStorage({//缓存用户登陆状态
			    key: 'userInfo',  
			    data: provider
			}) 
			
			// console.log("user_info",state.userInfo);
			// console.log("token",state.token);
			// console.log("exp_time",state.exp_time);
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({  
                key: 'userInfo'  
            })
		},
		reuserinfo(state,userinfo) {
			state.userInfo.TotalProfits = userinfo.TotalProfits
			state.userInfo.TeamMemNums = userinfo.TeamMemNums
			state.userInfo.OrderNums = userinfo.OrderNums
			state.userInfo.BalanceProfits = userinfo.BalanceProfits
			state.userInfo.Nick = userinfo.Nick
			state.userInfo.AgtName = userinfo.AgtName
			state.userInfo.HeadImgUrl = userinfo.HeadImgUrl
		}
	},
	actions: {
	
	}
})

export default store
